package chess;

import java.awt.Color;
import java.util.HashSet;
import java.util.Set;

public class Knight extends Piece{

	private String name;
	private String type;
	private Color color;
	private Coordinate co;
	private boolean selected;

	public Knight(String name, String type, Color color, Coordinate co){

		this.name= name;
		this.type= type;
		this.color= color;
		this.co= co;
	}

	public Set<Coordinate> getPossibleCoordinates(){
		int coX= co.getX();
		int coY= co.getY();
		Set<Coordinate> coords= new HashSet<Coordinate>();
		Set<Coordinate> posCoords= new HashSet<Coordinate>();
		coords.add(new Coordinate(coX+2, coY+1));
		coords.add(new Coordinate(coX+2, coY-1));
		coords.add(new Coordinate(coX-2, coY+1));
		coords.add(new Coordinate(coX-2, coY-1));
		coords.add(new Coordinate(coX+1, coY+2));
		coords.add(new Coordinate(coX+1, coY-2));
		coords.add(new Coordinate(coX-1, coY+2));
		coords.add(new Coordinate(coX-1, coY-2));
		for (Coordinate c: coords){
			if (GameRunner.board.isValid(c)){
				if (GameRunner.board.isOccupied(c)){
					if (GameRunner.board.getPiece(c).getColor()!= color){
						posCoords.add(c);
					}
				}
				else 
					posCoords.add(c);
			}
		}
		return posCoords;
	}

	public void moveTo(Coordinate c){
		this.setCoordinate(c);
	}

	public Coordinate getCoordinate(){
		return co;
	}

	public String getType(){
		return type;
	}

	public void setCoordinate(Coordinate c){
		co= c;
		GameRunner.board.setPieceToCoordinate(c,this);
	}
	
	public void setCoordinate(Coordinate c, Grid g){
		co= c;
		g.setPieceToCoordinate(c, this);
	}

	public String getName(){
		return name;
	}

	public Color getColor(){
		return color;
	}
	
	public String toString(){
		return name + ", " + type + ", " + color.toString() + co.toString();
	}
	
	boolean hasMoved() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void setSelected(boolean b) {
		selected = b;
	}
	
	@Override
	public boolean isSelected() {
		return selected;
	}


}